﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#if !WINDOWS_PHONE


#endif

namespace DARE
{
    [AttrTypeDependentSerializable(typeof(DARE.Save.DataStructures.CThirdPersonCameraData))]
    public class CThirdPersonCamera : CCamera
    {

    #region fields

        private Vector3 m_followLookAtOffset;

        //private CNode m_nodeFollow = null;
        //private Vector3 m_followPosition = new Vector3(0.0f, 5.0f, 8.0f);
        //private float m_zoom = 0.0f; // to do
        //private Quaternion m_followOrientation = Quaternion.Identity;
        //private Vector3 m_followPos;
        //private Vector3 m_pos;
        //private bool m_interpolate = true;
        //private float m_interpolateSpeed = 0.005f;

    #endregion

    #region properties

        /// <summary>
        /// Smooth the camera.
        /// Get if the camera is smoothed.
        /// Set the smooth on the camera.
        /// </summary>
        public bool Smooth
        {
            get { return m_node.Smooth; }
            set { m_node.Smooth = value; }
        }

        /// <summary>
        /// Amount of smooth. See node Smooth for more informations.
        /// Get the amount of smooth on the camera.
        /// Set the amount of smooth on the camera.
        /// </summary>
        public float SmoothAmount
        {
            get { return m_node.SmoothAmount; }
            set { m_node.SmoothAmount = value; }
        }

        /// <summary>
        /// The follow node is the node that the camera will automaticaly follow at a "FollowPosition" offset.
        /// Get the node it follows.
        /// Set the node to follow.
        /// </summary>
        public CNode FollowNode
        {
            get { return m_node.Parent; }
            set 
            {
                m_node.SetParent(value);
                m_node.LookAt(m_node.Parent.Position + m_followLookAtOffset);
            }
        }

        /// <summary>
        /// The follow position is relative to the node's position it follows.
        /// A camera with a follow position of 0, 1, 0 will always be over the node it follows.
        /// Get the follow position.
        /// Set the follow position.
        /// </summary>
        public Vector3 FollowPosition
        {
            get { return m_node.RelativePosition; }
            set
            {
                m_node.RelativePosition = value;
                m_node.LookAt(m_node.Parent.Position + m_followLookAtOffset);
            }
        }

        /// <summary>
        /// By default the camera look at the node it follows. But it 
        /// can be changed with an offset.
        /// Get the lookat offset.
        /// Set the lookat offset.
        /// </summary>
        public Vector3 FollowLookAtOffset
        {
            get { return m_followLookAtOffset; }
            set
            {
                m_followLookAtOffset = value;
                m_node.LookAt(m_node.Parent.Position + m_followLookAtOffset);
            }
        }

        //public CThirdPersonCamera(string name, CRender3D render) : 
        //    base(name, render)
        //{}

    #endregion

    #region ctor

        /// <summary>
        /// Create a third person camera with a name.
        /// The third person camera follow a node.
        /// </summary>
        /// <param name="name"></param>
        public CThirdPersonCamera(string name) :
            base(name)
        { }

    #endregion


        #region methods

        /// <summary>
        /// Update the camera, called by the camera manager.
        /// </summary>
        /// <param name="gameTime">GameTime.</param>
        public override void Update(GameTime gameTime)
        {
            m_needUpdateView = true;
        }

        #endregion

    }
}
